package com.hengda.museumonline.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.hengda.museumonline.base.BasePager;

import java.util.ArrayList;

/**
 * @author：JFWU on 2016/9/10 15:19
 * @E-mail：jeffy12138@126.com
 */
public class ContentAdapter extends PagerAdapter {
    private ArrayList<View> mPagers;
    boolean isFirstTextureMapView = true;
    boolean isFirstTextureMapView1 = true;
    public ContentAdapter(ArrayList<View> pagers) {
        mPagers = pagers;
    }

    @Override
    public int getCount() {
        return mPagers.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        System.out.println("position:"+position);
        if (position != 1&&position != 2) {
            container.addView(mPagers.get(position));
        }

        //TextureMapview 只会添加一次
        if (isFirstTextureMapView && position == 1) {
            isFirstTextureMapView = false;
            container.addView(mPagers.get(position));
        }
        if (isFirstTextureMapView1 && position == 2) {
            isFirstTextureMapView1 = false;
            container.addView(mPagers.get(position));
        }
        return mPagers.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (position == 1|| position == 2) {
            //mapview不会destory
            return;
        }
        container.removeView(mPagers.get(position));
    }
}
